/*
GeorgeLib
Collider.h
Under MIT License
*/

#ifndef __SPHERECOLLIDER_H__
#define __SPHERECOLLIDER_H__

#include "stdafx.h"
#include "Collider.h"

namespace GeorgeLib
{
	/// @brief A simple sphere collider using radii for calculations
	class DLLEXPORT SphereCollider : public Collider
	{
	public:
		/// Constructor
		SphereCollider(void);
		/// Constructor : with a size value
		SphereCollider(float radius);
		/// Constructor : copy from an existing SphereCollider
		SphereCollider(const SphereCollider& Sphere);
		~SphereCollider(void);

		/// Check if a Collider is intersecting with this Collider
		/// @param collider The other Collider to check containment with
		bool Collides(Collider* collider);

		/// Check if a Collider is within the bounds of this Collider
		/// @param collider The other Collider to check containment with
		bool Contains(Collider* collider);

		/// Check if a point in space is within the bounds of this Collider
		/// @param point The point to check containment with
		bool Contains(vec3 point);

		/// Makes sure a Collider is within the constrains of the bounds of this Collider
		/// @param collider The other Collider to contain
		void Contain(Collider* collider);

		/// Makes sure a point in space is within the bounds of this Collider
		/// @param point The point to contain
		void Contain(vec3& point);

		/// Check if a Collider is a SphereCollider
		/// @param collider The other Collider to check it's base class
		static bool IsSphere(const Collider& collider);

		/// Cast a Collider pointer to a SphereCollider pointer
		/// @param collider The pointer to a Collider
		/// @remarks Return value will be NULL if collider is not a SphereCollider
		static SphereCollider* CastCollider(Collider* const collider);

		float radius() { return _radius; }
		void radius(float r) { _radius = r; _radiusSqr = r * r; }
		float radiusSqr() { return _radiusSqr; }

		/// Returns the minimum coordinates that lie on this sphere
		vec3 min()
		{
			vec3 boxMin = wPos - _radius;
			return boxMin * (_radius / boxMin.magnitude());
		}

		/// Returns the maximum coordinates that lie one this sphere
		vec3 max()
		{
			vec3 boxMax = wPos + _radius;
			return boxMax * (_radius / boxMax.magnitude());
		}

	private:
		/// The radius of the sphere, measured in the SphereCollider's local space
		float _radius;
		float _radiusSqr;
	};
}

#endif // __SPHERECOLLIDER_H__